<template>
  <view class="games-container">
    <!-- 顶部导航栏 -->
    <view class="navbar">
      <view class="navbar-left" @click="navigateBack">
        <!-- <uni-icons type="left" size="24" color="#fff"></uni-icons> -->
      </view>
      <view class="navbar-title">游戏中心</view>
      <view class="navbar-right">
        <uni-icons type="setting" size="24" color="#fff" @click="openSettings"></uni-icons>
      </view>
    </view>

    <!-- 页面内容 -->
    <scroll-view class="content" scroll-y>
      <!-- 头部横幅 -->
      <view class="header-banner">
        <image 
          src="https://picsum.photos/id/237/750/300" 
          mode="widthFix" 
          class="banner-image"
          alt="游戏中心横幅"
        ></image>
        <view class="banner-overlay">
          <view class="banner-title">精选游戏</view>
          <view class="banner-subtitle">发现更多乐趣</view>
        </view>
      </view>

      <!-- 游戏列表 -->
      <view class="games-list">
        <view 
          class="game-card" 
          v-for="(game, index) in games" 
          :key="index"
          @click="navigateToGame(game.id)"
          :style="{ '--card-bg': game.bgColor }"
        >
          <!-- 游戏封面图 -->
          <view class="game-cover-container">
            <image 
              :src="game.coverUrl" 
              mode="aspectFill" 
              class="game-cover"
              :alt="game.name + '封面'"
            ></image>
            <!-- 游戏标签 -->
            <view class="game-tags">
              <view class="game-tag" v-for="(tag, tIndex) in game.tags" :key="tIndex">
                {{ tag }}
              </view>
            </view>
          </view>
          
          <!-- 游戏信息 -->
          <view class="game-info">
            <view class="game-name-rating">
              <view class="game-name">{{ game.name }}</view>
              <view class="game-rating">
                <uni-icons type="star" size="14" color="#ffcc00"></uni-icons>
                <text>{{ game.rating }}</text>
              </view>
            </view>
            
            <view class="game-desc">{{ game.description }}</view>
            
            <view class="game-stats">
              <view class="stat-item">
                <uni-icons type="eye" size="14" color="#999"></uni-icons>
                <text>{{ game.plays }}</text>
              </view>
              <view class="stat-item">
                <uni-icons type="user" size="14" color="#999"></uni-icons>
                <text>{{ game.players }}</text>
              </view>
            </view>
          </view>
          
          <!-- 进入游戏按钮 -->
          <view class="play-button">
            <text>开始游戏</text>
            <uni-icons type="right" size="16" color="#fff"></uni-icons>
          </view>
        </view>
      </view>
      
      <!-- 底部留白 -->
      <view class="bottom-space"></view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 游戏数据
      games: [
        {
          id: 1,
          name: "数字消除大师",
          coverUrl: "https://picsum.photos/id/1/400/240",
          description: "挑战你的数字敏感度，通过策略消除数字获得高分",
          tags: ["益智", "休闲"],
          rating: 4.8,
          plays: "12.5万+",
          players: "3.2万",
          bgColor: "linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)"
        },
        {
          id: 2,
          name: "极速赛车",
          coverUrl: "https://picsum.photos/id/20/400/240",
          description: "体验风驰电掣的快感，超越对手成为赛道王者",
          tags: ["竞速", "刺激"],
          rating: 4.6,
          plays: "8.7万+",
          players: "2.5万",
          bgColor: "linear-gradient(135deg, #fff1eb 0%, #ace0f9 100%)"
        },
        {
          id: 3,
          name: "策略塔防",
          coverUrl: "https://picsum.photos/id/30/400/240",
          description: "部署防御塔，制定战略，抵御敌人的一波波进攻",
          tags: ["策略", "塔防"],
          rating: 4.7,
          plays: "15.3万+",
          players: "4.1万",
          bgColor: "linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%)"
        },
        {
          id: 4,
          name: "记忆大挑战",
          coverUrl: "https://picsum.photos/id/40/400/240",
          description: "锻炼你的记忆力，在限定时间内匹配所有卡片",
          tags: ["益智", "记忆"],
          rating: 4.5,
          plays: "7.9万+",
          players: "1.8万",
          bgColor: "linear-gradient(135deg, #fdfcfb 0%, #e2d1c3 100%)"
        }
      ]
    };
  },
  methods: {
    // 返回上一页
    navigateBack() {
      uni.navigateBack({
        delta: 1
      });
    },
    
    // 打开设置
    openSettings() {
      uni.showToast({
        title: "设置功能待实现",
        icon: "none"
      });
    },
    
    // 跳转到游戏
    navigateToGame(gameId) {
      // 实际项目中，这里会跳转到对应的游戏页面
      uni.navigateTo({
        url: `/pages/games/detail?id=${gameId}`
      });
    }
  }
};
</script>

<style scoped lang="scss">
.games-container {
  background-color: #f0f2f5;
  min-height: 100vh;
}

// 导航栏样式
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background-color: #1677ff;
  
  .navbar-left, .navbar-right {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .navbar-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    flex: 1;
    text-align: center;
  }
}

// 内容区域
.content {
  padding-bottom: 20px;
}

// 头部横幅
.header-banner {
  position: relative;
  margin: 16px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  
  .banner-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
  }
  
  .banner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.7), rgba(0,0,0,0.2));
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 24px;
    
    .banner-title {
      font-size: 24px;
      font-weight: 700;
      color: #fff;
      margin-bottom: 8px;
      text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }
    
    .banner-subtitle {
      font-size: 16px;
      color: #f0f0f0;
      text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    }
  }
}

// 游戏列表
.games-list {
  padding: 0 16px;
  
  .game-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    
    &:active {
      transform: translateY(2px);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }
    
    // 游戏封面
    .game-cover-container {
      position: relative;
      width: 100%;
      height: 180px;
      border-radius: 12px;
      overflow: hidden;
      margin-bottom: 16px;
      
      .game-cover {
        width: 100%;
        height: 100%;
      }
      
      .game-tags {
        position: absolute;
        top: 12px;
        left: 12px;
        display: flex;
        gap: 8px;
        
        .game-tag {
          background-color: rgba(0, 0, 0, 0.6);
          color: #fff;
          font-size: 12px;
          padding: 4px 8px;
          border-radius: 12px;
          backdrop-filter: blur(4px);
        }
      }
    }
    
    // 游戏信息
    .game-info {
      margin-bottom: 16px;
      
      .game-name-rating {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
        
        .game-name {
          font-size: 18px;
          font-weight: 600;
          color: #333;
        }
        
        .game-rating {
          display: flex;
          align-items: center;
          font-size: 14px;
          color: #333;
          
          uni-icons {
            margin-right: 4px;
          }
        }
      }
      
      .game-desc {
        font-size: 14px;
        color: #666;
        line-height: 1.5;
        margin-bottom: 12px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
      
      .game-stats {
        display: flex;
        gap: 16px;
        
        .stat-item {
          display: flex;
          align-items: center;
          font-size: 12px;
          color: #999;
          
          uni-icons {
            margin-right: 4px;
          }
        }
      }
    }
    
    // 开始游戏按钮
    .play-button {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      background-color: #1677ff;
      color: #fff;
      font-size: 16px;
      font-weight: 500;
      padding: 12px;
      border-radius: 8px;
      transition: background-color 0.2s ease;
      
      &:active {
        background-color: #0f5fcc;
      }
    }
  }
}

// 底部留白
.bottom-space {
  height: 20px;
}
</style>
